package cn.wp.ewallet.upms.service.impl;

import cn.wp.common.core.authentication.AuthenticationContext;
import cn.wp.common.core.authentication.AuthenticationInfo;
import cn.wp.common.core.model.WpTree;
import cn.wp.common.core.util.TreeUtil;
import cn.wp.ewallet.common.model.EwalletAuthenticationInfo;
import cn.wp.ewallet.upms.dao.BsFuncMenuInfoDao;
import cn.wp.ewallet.upms.model.entity.BsFuncMenuInfoDo;
import cn.wp.ewallet.upms.service.BsFuncMenuInfoService;

import org.springframework.stereotype.Service;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;


/**
 * 功能菜单-业务逻辑层实现
 * Created by zhangyongli on 2019/12/25
 */
@Service
public class BsFuncMenuInfoServiceImpl implements BsFuncMenuInfoService {

    @Autowired
    private BsFuncMenuInfoDao bsFuncMenuInfoDao;

    @Autowired
    private AuthenticationContext authenticationContext;

    @Override
    public List<WpTree> getBsFuncMenuInfoBySystemUserId() {

        //获取当前登录用户
        AuthenticationInfo authenticationInfo = authenticationContext.currentUser();

        String userId = authenticationInfo.getId();

        //查询用户授权的功能
        List<BsFuncMenuInfoDo> bsFuncMenuInfoDoList = bsFuncMenuInfoDao.selectBsFuncMenuInfoBySystemUserId(userId);
        TreeUtil.Mapping mapping = new TreeUtil.Mapping();
        mapping.addMapping(WpTree.TREE_ID, "menuId");
        mapping.addMapping(WpTree.TREE_NAME, "menuName","title");
        mapping.addMapping(WpTree.TREE_PARENT_ID, "parMenuId");
        mapping.addMapping(WpTree.TREE_URL, "urlAddr","href");
        mapping.addMapping(WpTree.TREE_ICON, "menuIcon","icon");
        return TreeUtil.build(bsFuncMenuInfoDoList, "0", "parMenuId", mapping, new TreeUtil.Builder<BsFuncMenuInfoDo>() {
            @Override
            public void build(WpTree tree, BsFuncMenuInfoDo o) {
                tree.put("target","_self");
            }
        });

    }

}